package com.nosnow.edu.controller;


import com.nosnow.common.utils.R;
import com.nosnow.edu.entity.subject.OneSubject;
import com.nosnow.edu.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author bingheng
 * @since 2020-04-04
 */
@Api(description = "课程科目")
@RestController
@RequestMapping("/edu/subject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    @ApiOperation(value="读取excel中的数据")
    @PostMapping("uploadSubject")
    public R uploadSubject(MultipartFile file) {
        try{
            // 获取上传过来的文件
            eduSubjectService.saveSubject(file, eduSubjectService);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation(value="课程分类列表树")
    @GetMapping("getSubjectThree")
    public R getSubjectThree() {
        List<OneSubject> list = eduSubjectService.getAllOneTwoSubject();
        return R.ok().data("list", list);
    }


}

